package mo.offer_special;

import java.util.ArrayList;
import java.util.List;

public class L080 {

    private List<Integer> combination = new ArrayList<>();
    private List<List<Integer>> ret = new ArrayList<>();

    public List<List<Integer>> combine(int n, int k) {
        for (int i = 1; i <= n; i++) {
            combination.add(i);
            dfs(combination, i, n, k);
            combination.remove(combination.size()-1);
        }
        return ret;
    }

    private void dfs(List<Integer> tmp, int cur, int n, int k) {
        if (tmp.size() == k) {
            ret.add(new ArrayList<>(tmp));
        }
        for (int i = cur+1; i <= n; i++) {
            tmp.add(i);
            dfs(tmp, i, n, k);
            tmp.remove(tmp.size()-1);
        }
    }

    public static void main(String[] args) {
        L080 test = new L080();
        System.out.println(test.combine(4, 2));
    }

}
